<?php


namespace App\Commons\Domain\Module\Exchange\Model;


use App\Commons\Domain\Core\Model;
use App\Commons\Domain\Module\Financial\Model\Wallet;
use App\Commons\Domain\Module\UserCenter\Model\Member;
use Illuminate\Support\Carbon;


/**
 * App\Commons\Domain\Module\Exchange\Model\Advertising
 *
 * @property int $id
 * @property Carbon $created_at
 * @property Carbon $updated_at
 * @property string $uid 广告发布方
 * @property int $wallet_id 钱包id
 * @property int $type 广告类型，1卖出，2买入
 * @property string $price 单价
 * @property string $min_limit 单笔订单最低交易额
 * @property string $max_limit 单笔订单最高交易额
 * @property int $pay_time_limit 付款期限，单位分钟
 * @property int $status 状态，0上架、1下架、2关闭
 * @property string $quantity 数量
 * @property string|null $remark 备注
 * @property int $pay_type 支持的收付款方式：1银行卡、2支付宝、3微信支付
 * @property-read Member $member
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Commons\Domain\Module\Exchange\Model\Order[] $orders
 * @property-read int|null $orders_count
 * @property-read Wallet $wallet
 * @method static \Illuminate\Database\Eloquent\Builder|Advertising newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Advertising newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Advertising query()
 * @method static \Illuminate\Database\Eloquent\Builder|Advertising whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Advertising whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Advertising whereMaxLimit($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Advertising whereMinLimit($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Advertising wherePayTimeLimit($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Advertising wherePayType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Advertising wherePrice($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Advertising whereQuantity($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Advertising whereRemark($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Advertising whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Advertising whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Advertising whereUid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Advertising whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Advertising whereWalletId($value)
 * @mixin \Eloquent
 */
class Advertising extends Model
{
    protected $appends = ['pay_name'];

    // 现价
    public function getPayNameAttribute()
    {
        if (isset($this->attributes['pay_type'])) {
            $name = ['银行卡', '支付宝', '微信支付'];
            return $name[$this->attributes['pay_type'] - 1];
        }
        return '';
    }

    /**
     * 用户拥有的广告
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function member()
    {
        return $this->belongsTo(Member::class, 'uid', 'uid');
    }

    /**
     * 所属币种钱包
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function wallet()
    {
        return $this->belongsTo(Wallet::class, 'wallet_id', 'id');
    }

    /**
     * 广告拥有的交易订单
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function orders()
    {
        return $this->hasMany(Order::class, 'advertising_id', 'id');
    }

}
